﻿@{
    ViewBag.Title = "Test";
}
<form>
    <h2>Test</h2>
    <input type="button" value=" 新 建 " />
    <table>
        <tbody data-bind="foreach: Items">
            <tr>
                <td data-bind="html: $data.Id"></td>
                <td data-bind="html: $data.Name"></td>
                <td data-bind="html: $data.Sex"></td>
                <td>
                    <input type="text" data-bind="value: $data.Name, event: { blur: $root.InputOnBlur }" />
                </td>
                <td>
                    <select data-bind="optionsText:$data.Sex">
                        <option value="男">男</option>
                        <option value="女">女</option>
                    </select>
                </td>
                
            </tr>
        </tbody>
    </table>
    <h2>test</h2>
</form>
<script type="text/javascript">
    //Array.prototype.filter=function(fn){
    //    console.log(this);
    //}
    var item = [{ "Id": 1, "Name": "李四", "Sex": "男" }
            , { "Id": 2, "Name": "张三", "Sex": "女" }];
    function viewModel() {
        var self = this;
        self.InputOnBlur = function (data) {
            var all = self.Items(); 
            self.Items([]);
            self.Items(all);
            console.log(data);
        }
        self.Items = ko.observableArray(JSON.parse(JSON.stringify(item)));
    }
    var vm = new viewModel();
    ko.applyBindings(vm);


</script>
